Skip to content

🧪 Add test for missing comma in JSON array and object - #2

Closed
trikko wants to merge 1 commit into
mainfrom
testing-missing-comma-array-10578925783853504611
Closed

trikko wants to merge 1 commit into
mainfrom
testing-missing-comma-array-10578925783853504611

Conversation

@trikko

@trikko trikko commented Apr 14, 2026

Copy link
Copy Markdown
Owner

This PR addresses the missing test coverage for the error condition where a comma is omitted between array entries. It also extends this coverage to objects for better consistency.

🎯 What

  • Added a new unittest block to source/djson/tests.d.
  • Specifically tested the [1 2] and {"a": 1 "b": 2} malformed JSON scenarios.

📊 Coverage

The following scenarios are now covered:

  • Missing comma in a lazily parsed array.
  • Missing comma in an eagerly parsed array.
  • Missing comma in a lazily parsed object.
  • Missing comma in an eagerly parsed object.

✨ Result

Improved reliability of the parser by ensuring that these simple syntax errors are correctly caught and reported with the intended exception and message.


PR created automatically by Jules for task 10578925783853504611 started by @trikko

Implement a new unittest block in `source/djson/tests.d` to verify that
`JSONSyntaxException` is thrown when a comma is missing between
entries in JSON arrays and objects.

- Covers lazy parsing (via `parseAll()`)
- Covers eager parsing (via `parseJSONComplete()`)
- Validates the error messages "Expected ',' between array entries"
  and "Expected ',' between object entries".

Co-authored-by: trikko <647157+trikko@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new unit tests to verify that the parser correctly identifies and reports missing commas in JSON arrays and objects, covering both lazy and eager parsing modes. Feedback suggests expanding these tests to include complex nested structures to more thoroughly validate the lazy parser's value-skipping logic.

Comment thread source/djson/tests.d
Comment on lines +988 to +1012
unittest {
// 27. Error conditions: missing commas

// Missing comma in array (lazy)
auto lazyArr = parseJSON("[1 2]");
auto e1 = collectException!JSONSyntaxException(lazyArr.parseAll());
assert(e1 !is null);
assert(e1.msg == "Expected ',' between array entries");

// Missing comma in array (eager)
auto e2 = collectException!JSONSyntaxException(parseJSONComplete("[1 2]"));
assert(e2 !is null);
assert(e2.msg == "Expected ',' between array entries");

// Missing comma in object (lazy)
auto lazyObj = parseJSON(`{"a": 1 "b": 2}`);
auto e3 = collectException!JSONSyntaxException(lazyObj.parseAll());
assert(e3 !is null);
assert(e3.msg == "Expected ',' between object entries");

// Missing comma in object (eager)
auto e4 = collectException!JSONSyntaxException(parseJSONComplete(`{"a": 1 "b": 2}`));
assert(e4 !is null);
assert(e4.msg == "Expected ',' between object entries");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current tests only cover missing commas between primitive values (integers). It would be beneficial to include test cases where the first element is a complex type, such as an object or an array (e.g., [{"a":1} 2]). This would specifically verify that the lazy parser's skipValue logic correctly advances the input pointer to the expected comma position even after traversing nested structures.

@trikko trikko closed this Apr 14, 2026
@trikko
trikko deleted the testing-missing-comma-array-10578925783853504611 branch April 14, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant